<template>
    <div class="teamMeeting" id="teamMeeting">
        <!-- 搜索栏 -->
        <searchBar :activeIndex="activeIndex" @changeNav="changeNav" @getSearchBarData="getSearchBarData"></searchBar>
        <!-- 列表栏 -->
        <meetingTable ref="tableRef" @showAddDialog="showAddDialog"></meetingTable>
        <!-- 分页 -->
        <div class="pagination">
            <CommonPagination2 :pageNum="searchData.pageNum" :pageSize="searchData.pageSize" :pageTotal="total"
                @pageFunc="pageFunc" @sizeChange="sizeChange"></CommonPagination2>
        </div>
        <!-- 新增 -->
        <meetingAdd :dialogVisible="dialogVisible" @closeDialog="closeDialog" @confirmDialog="confirmDialog"></meetingAdd>
    </div>
</template>


<script setup lang="ts">
import searchBar from "./components/searchBar.vue"
import meetingTable from "./components/table.vue"
import meetingAdd from "./components/meetingAdd.vue"

let activeIndex = ref(0);

const tableRef = ref<any>()

const runRef = ref<any>(null); //运行班组会议组件

const overhaulRef = ref<any>(null); //检修班组会议组件
//是否打开新增弹窗
const dialogVisible = ref(false);

const showAddDialog = ()=>{
  dialogVisible.value = true;
}

//关闭新增弹窗
const closeDialog = ()=>{
  dialogVisible.value = false;
}

//新增弹窗点击保存
const confirmDialog = ()=>{
    dialogVisible.value = false;
    tableRef.value.getData(); // 刷新页面
}

// 放置页码及相关数据
let searchData = reactive({
    pageNum: 1, //当前页
    pageSize: 10, //每页条目数
    params: {
        name: '',
        configState: '',
        state: '',
    }
})

let total = ref(0);

//切换导航栏
const changeNav = (val: number) => {
    activeIndex.value = val;
    if (val == 0) {
        // runRef.value.getList();
    } else if (val == 1) {
        // overhaulRef.value.getList();
    }
}

// 获取总条数
const getTotal = (num: number) => {
    total.value = num;
}

// 页数改变事件(上一页,下一页,跳转到某一页)
const pageFunc = (pageNum: number) => {
    searchData.pageNum = pageNum;
    // 触发获取数据函数
    if (tableRef.value) {
        tableRef.value.getData();
    }
}

//每页条数改变
const sizeChange = (pageSize: number) => {
    searchData.pageSize = pageSize;
    tableRef.value?.getData();
}

// 查
const getSearchBarData = (data: any) => {
    searchData.params = data;
    if (tableRef.value) {
        searchData.pageNum = 1;
        tableRef.value.getData();
    }
}


</script>


<style lang="scss" scoped>
.teamMeeting {
    padding: 0px 15px;
    background-color: rgb(229, 229, 229);
    height: 100%;
    position: relative;

    .pagination {
        position: absolute;
        right: 50px;
        bottom: 40px;
    }
}
</style>